<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>生态瞬时评估 - 主页</title>

    <meta name="keywords" content="">
    <meta name="description" content="">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="../favicon.ico">
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <h3 class="col-sm-offset-3 col-sm-6 text-center">添加人员</h3>
        </div>
        <div class="row">
            <div class="col-sm-offset-3 col-sm-6">
                <form class="form-horizontal" style="margin-top: 20px">
                    <div class="form-group">
                        <label for="user" class="col-sm-3 control-label">用户名：</label>
                        <div class="col-sm-8">
                            <input type="text" placeholder="请输入用户名" class="form-control" id="user">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="pwd" class="col-sm-3 control-label">密码：</label>
                        <div class="col-sm-8">
                            <input type="password" placeholder="请输入密码" class="form-control" id="pwd">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="user-name" class="col-sm-3 control-label">真实姓名：</label>
                        <div class="col-sm-8">
                            <input type="text" placeholder="请输入真实姓名" class="form-control" id="user-name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="user-name" class="col-sm-3 control-label">联系方式：</label>
                        <div class="col-sm-8">
                            <input type="text" placeholder="请输入正确的联系方式" class="form-control" id="tel">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">性别：</label>
                        <div class="col-sm-8" id="sex">
                            <div class="radio-inline i-checks">
                                <label>
                                    <input type="radio" value="0" name="sex"> <i></i> 男</label>
                            </div>
                            <div class="radio-inline i-checks">
                                <label>
                                    <input type="radio" value="1" name="sex"> <i></i> 女</label>
                            </div>
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">出生日期：</label>
                        <div class="col-sm-8">
                            <input type="text" class="laydate-icon form-control layer-date" id="birth-date" placeholder="选择出生日期">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">角色：</label>
                        <div class="col-sm-8" id="role">
                            <div class="radio-inline i-checks">
                                <label>
                                    <input type="radio" value="0" name="role"> <i></i> 实验者</label>
                            </div>
                            <div class="radio-inline i-checks">
                                <label>
                                    <input type="radio" value="1" name="role"> <i></i> 被试者</label>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-offset-3 col-sm-8">
                        <input type="button" id="addBtn" value="添加" class="btn btn-primary btn-block">
                    </div>
                </form>
            </div>
        </div>

    </div>




    <script src="../js/jquery.min.js?v=2.1.4"></script>
    <script src="../js/bootstrap.min.js?v=3.3.6"></script>
    <!-- layerDate plugin javascript -->
    <script src="../js/plugins/layer/laydate/laydate.js"></script>
    <!--icheck-->
    <script src="../js/plugins/iCheck/icheck.min.js"></script>
    <script>
        //外部js调用
        laydate({
            elem: '#birth-date', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
            event: 'focus' //响应事件。如果没有传入event，则按照默认的click
        });


    </script>
    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });

            // 获取性别值
            // var radioVal = '';
            // $("input:radio[name='sex']").on('ifChecked', function (event) {
            //     radioVal = $(this).val()
            //     console.log(radioVal);
            // });
            $("#addBtn").on("click", function () {
                $("#addBtn").attr("disabled","true");
                var token = sessionStorage.getItem("token");
                var $uname = $("#user").val();
                var $pwd = $("#pwd").val();
                var $rname = $("#user-name").val();
                var $sex = $("#sex .checked").find("input").val()==0?"男":"女";
                var $tel = $("#tel").val();
                var $role = $("#role .checked").find("input").val()==0?"MANAGER":"SUBJECT";
                var $birthday = $("#birth-date").val();
                var dataInfo = JSON.stringify({"userName":$uname, "password":$pwd,"realName":$rname,"gender":$sex,"birthday":$birthday,"telephone":$tel,"role":$role});
                $.ajax({
                    type:"POST",
                    url:"http://123.206.18.189:8080/users",
                    contentType:"application/json",
                    beforeSend: function(xhr){xhr.setRequestHeader('authToken', token);},
                    data:dataInfo,
                    dataType:'json',
                    success:function (res) {
                        console.log(res);
                    },
                    error:function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log(XMLHttpRequest.status);
                        console.log(XMLHttpRequest.readyState);
                        console.log(textStatus);
                    },
                    complete:function (XMLHttpRequest) {
                        if(XMLHttpRequest.status==200){
                            alert("人员添加成功！");
                            window.location.reload();
                        }else{
                            alert("人员添加失败，请重新填写！");
                            window.location.reload()
                        }

                    }
                })

            })
        })
    </script>

</body>
</html>